home *** CD-ROM | disk | FTP | other *** search
/ Web Page Construction Kit 3.0 / Web Page Construction Kit 3.0.iso / pc / source / 3rdparty / java / jdesnpro / data.1 / JDPLayout1.java < prev    next >
Encoding:
Text File  |  1996-07-24  |  11.9 KB  |  444 lines

  1. >XXX0445  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13.  
  14.  
  15. >003public class <JDPUserBill> extends JDPClassLayout {
  16.  
  17.     JDPUser user;
  18.     JDPJagg jaggSQL;
  19.     JDPWhereClause jdpWhereClause;
  20.     JDPSearchResults searchResults;
  21.  
  22.     String[] psortChoice;
  23.     String[] pdisplayChoice;
  24.     int itemIndex;
  25.     boolean insertRequested = false;
  26.     boolean deleteRequested = false;
  27.     String pfromWhereClause;
  28.  
  29.     //
  30.     //  Declare screen components
  31.     //
  32. >004    <TextField username>;
  33.  
  34.  
  35.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  36.  
  37.         this.user = user;
  38.         //
  39.         //  Set JAGG settings for this class
  40.         //
  41.         jaggSQL = new JDPJagg(user.jaggPath);
  42.         jaggSQL.setNULL("space");
  43. >997        jaggSQL.setMRW("<maxRows>");
  44. >998        jaggSQL.setDSN("<datasource>");
  45. >999        jaggSQL.setCSTR("<connectstr>");
  46.  
  47.         setLayout(new BorderLayout());
  48.         setFont(user.plainFont);
  49.  
  50.         Panel mainPanel = new Panel();
  51.         mainPanel.setLayout(new BorderLayout());
  52.         Panel centerPanel = new Panel();
  53.         centerPanel.setLayout(new BorderLayout());
  54.         Panel centerMainPanel = new Panel();
  55.         centerMainPanel.setLayout(new BorderLayout());
  56.         Panel centerTopPanel = new JDPScrollPanel();
  57.         Panel leftPanel = new Panel();
  58.         leftPanel.setLayout(new BorderLayout());
  59.         
  60.         //
  61.         //  Define parameters for JDPSearchResults
  62.         //
  63. >005        String pselectFields = "<>"; String[] psdisplayFields = {<>};
  64. >006        pfromWhereClause = "<FROM JDPUser WHERE >";
  65.  
  66. >007        psortChoice = new String[<5>];
  67. >008        psortChoice[<0>] = "<username>";
  68.  
  69. >009        String[] psortChoiceText = {<"Sort by User Name","Sort by Card Number">};
  70.         pdisplayChoice = psortChoice;
  71.  
  72. >010        boolean pdisplayCount = <true>;
  73. >011        String pcountText = "<Total Entries:>";
  74.     
  75.         //
  76.         //  Create an instance of screen components
  77.         //
  78. >012        <username> = new <TextField("",20)>;
  79.  
  80.         //
  81.         //  Initialise any choice components
  82.         //
  83.         loadChoices();
  84.  
  85.         //
  86.         //  Add components to the screen
  87.         //
  88. >013        centerTopPanel.add("Left",new JDPWrapLabel(user,"<User Name:>",Color.<labelColor>));
  89. >014        centerTopPanel.add("Right",centerR<0>);
  90.  
  91.         centerMainPanel.add("Center",centerTopPanel);
  92.         
  93.         // 
  94.         //  Set screen component attributes
  95.         //
  96. >039        <username>.setForeground(Color.<fcolor>);
  97. >040        <username>.setBackground(Color.<bcolor>);
  98.         
  99.         //
  100.         //  Add buttons to the bottom of the panel
  101.         //
  102.         if (moduleParameter.compareTo("Inquiry") == 0) {
  103. >041            <username>.setEditable(false);
  104.             String buttons[] = {""};
  105.             centerMainPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
  106.         } else {
  107. >042            <username>.setEditable(<editable>);
  108. >015            String buttons[] = {<"   Apply   ","Reset","New","Copy","Remove">};
  109.             centerMainPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
  110.         }
  111.         mainPanel.add("Center",centerMainPanel);
  112.         
  113.         //
  114.         //  Define parameters for JDPWhereClause
  115.         //
  116. >016        String[] pchooseFrom = new String[<7>];
  117. >017        pchooseFrom[<0>] = "<Account Name>";
  118.  
  119. >018        String[] pactualchooseFrom = new String[<7>];
  120. >019        pactualchooseFrom[<0>] = "<username>";
  121.  
  122. >020        String[][] pmatchUsing = new String[<7>][<7>];
  123. >021        pmatchUsing[<0>][<0>] = "<Begins with>";
  124.  
  125. >022        String[][] pactualmatchUsing = new String[<7>][<7>];
  126. >023        pactualmatchUsing[<0>][<0>] = "< like >";
  127.  
  128. >024        boolean[] constantIsString = new boolean[<7>];
  129. >025        constantIsString[<0>] = <true>;
  130.  
  131. >026        int[] constantLength = new int[<7>];
  132. >027        constantLength[<0>] = <20>;
  133.  
  134.         //
  135.         //  Add JDPWhereClause search panel
  136.         //
  137.         if (pchooseFrom.length > 0) {
  138. >028            jdpWhereClause = new JDPWhereClause(user, "<UserBill>", true, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  139.                                                 pmatchUsing, pactualmatchUsing, null, null,
  140.                                                 constantLength, constantIsString);
  141.             leftPanel.add("North",jdpWhereClause);
  142.         }
  143.         //
  144.         //  Add JDPSearchResults result list
  145.         //
  146.         if (psortChoice.length > 0) {
  147. >029            searchResults = new JDPSearchResults(user, <false>, jaggSQL, <false>, pselectFields, psdisplayFields, pfromWhereClause, psortChoiceText, psortChoice, pdisplayChoice, "<pinitChoice>", pdisplayCount, pcountText);
  148.             leftPanel.add("Center",searchResults);
  149.             mainPanel.add("West",leftPanel);
  150.         }
  151.  
  152. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",mainPanel,"North"));
  153.         if (psortChoice.length > 0) {
  154.             newSearch();
  155.         }
  156.         // repaint the panel
  157.         targetPanel.add("Center",this);
  158.         targetPanel.paintAll(targetPanel.getGraphics());
  159.         //
  160.         //  Add the handle to this panel to the global vector so other panels can
  161.         //  access this one
  162.         //
  163.         user.gParm.addElement(this);
  164.     }
  165.  
  166.     //
  167.     //  Handle screen events
  168.     //
  169.     public boolean handleEvent(Event e) {
  170.  
  171.         switch (e.id) {
  172.         case Event.ACTION_EVENT:
  173.             if (e.target instanceof List) {
  174.                 if (e.target.equals(searchResults.resultList)) {
  175.                     loadData();
  176.                     return true;
  177.                 }
  178.             }
  179.             if (e.target instanceof JDPTreePicker) {
  180.                 if (e.target.equals(searchResults.tree)) {
  181.                     loadData();
  182.                     return true;
  183.                 }
  184.             }
  185.             if (e.target instanceof Button) {
  186.                 String choice = (String)e.arg;
  187.                 if (choice.trim().compareTo("Apply") == 0) {
  188.                     if (checkFields()) {
  189.                         if (insertRequested) {
  190.                             saveData();
  191.                             newSearch();
  192.                         } else {
  193.                             saveData();
  194.                         }
  195.                     }
  196.                     return true;
  197.                 }
  198.                 if (choice.trim().compareTo("Reset") == 0) {
  199.                     loadData();
  200.                     return true;
  201.                 }
  202.                 if (choice.trim().compareTo("New") == 0) {
  203.                     insertRequested = true;
  204.                     clearFields();
  205.                     return true;
  206.                 }
  207.                 if (choice.trim().compareTo("Submit") == 0) {
  208.                     insertRequested = true;
  209.                     if (checkFields()) {
  210.                         saveData();
  211.                     }
  212.                     return true;
  213.                 }
  214.                 if (choice.trim().compareTo("Copy") == 0) {
  215.                     insertRequested = true;
  216.                     return true;
  217.                 }
  218.                 if (choice.trim().compareTo("Remove") == 0) {
  219.                     insertRequested = false;
  220.                     deleteRequested = true;
  221.                     saveData();
  222.                     newSearch();
  223.                     return true;
  224.                 }
  225.                 if (choice.trim().compareTo("Search") == 0) {
  226.                     insertRequested = false;
  227.                     deleteRequested = false;
  228.                     newSearch();
  229.                     return true;
  230.                 }
  231.                 return true;
  232.             }
  233.             if (e.target instanceof Choice) {
  234.                 return true;
  235.             }
  236.             if (e.target instanceof TextField) {
  237.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  238.                     insertRequested = false;
  239.                     deleteRequested = false;
  240.                     newSearch();
  241.                     return true;
  242.                 }
  243.                 checkFields();
  244.                 return true;
  245.             }
  246.             return false;
  247.  
  248.         case Event.KEY_PRESS:
  249.             if (e.key == '\t') {
  250.                 //  handle tabbing between components
  251.                 if (e.modifiers != Event.SHIFT_MASK) {
  252. >031                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  253.                 } else {
  254. >038                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  255.                 }
  256.                 return true;
  257.             }
  258.             return false;
  259.  
  260.         case Event.WINDOW_EXPOSE:
  261.             if (e.target instanceof JDPTabSelectTopPanel) {
  262.                 //
  263.                 //  This is where you place code to get executed when this panel is
  264.                 //  reactivated from the tab menu
  265.                 //
  266.                 return true;
  267.             }
  268.             return false;
  269.  
  270.         default:
  271.             return false;
  272.  
  273.         }
  274.     }
  275.  
  276.     //
  277.     //  Retrieve the handle to another panel so as to be able to interact with it
  278.     //
  279.     public void retrieveHandle() {
  280.  
  281.         for (int ix=0; ix<user.gParm.size(); ix++) {
  282.             //
  283.             //  Activate the next four lines of code to retrieve the handle to another 
  284.             //  Panel within your JDP system. Of course you should declare the variable 
  285.             //  at the top of this source instead of within this method so you can 
  286.             //  access it from all the methods within this class. You only need to 
  287.             //  substitute DemoClass with the name ouf your class. You should call this 
  288.             //  method from somewhere else in this class. To access a variable from 
  289.             //  your resulting class use:
  290.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  291.             //
  292. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  293. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  294. //                return;
  295. //            }
  296.         }
  297.     }
  298.  
  299.     //
  300.     //  The search button was pressed so rerun the query with the new search criteria
  301.     //
  302.     public void newSearch() {
  303.  
  304.         String whereClause;
  305.  
  306.         whereClause = pfromWhereClause;
  307.         if (jdpWhereClause != null) {
  308.             whereClause = whereClause + " AND " + jdpWhereClause.whereClause;
  309.         }
  310.         searchResults.setFromWhereClause(whereClause);
  311.         searchResults.clearList();
  312.         searchResults.loadList();
  313.     }
  314.  
  315.     //
  316.     //  Load the selected item
  317.     //
  318.     public void loadData() {
  319.  
  320.         StringTokenizer stok;
  321.  
  322.         int recCount = 0;
  323.         Vector results = new Vector();
  324.         String sep = jaggSQL.getSEP();
  325.         int actualRows = 0;
  326.         String row;
  327.         String tempText;
  328.  
  329.         if ((itemIndex = searchResults.getSelectedIndex()) < 0) {
  330.             clearFields();
  331.             return;
  332.         }
  333.  
  334. >032        String SQL = <SELECT username,firstname,lastname,status,cardnum,cardexpiry,cardname FROM JDPUser (NOLOCK) WHERE userid = " + thisuserid>;
  335.  
  336.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  337.         recCount = jaggSQL.execSQL(SQL, results);
  338.  
  339.         if(recCount == -1) {
  340.             System.out.println("loadData SQL: "+SQL);
  341.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
  342.             return;
  343.         }
  344.         if(recCount >= 1) {
  345.             row = (String)results.elementAt(0);
  346.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  347.                 stok = new StringTokenizer(row);
  348.  
  349. >033                <username>.setText(stok.nextToken(sep).trim());
  350.             }
  351.             if(recCount > 1) {
  352.                 user.mainmsg.setStatusMsg("Multiple records found - first match only displayed.", 10);
  353.             } else {
  354.                 user.mainmsg.clearStatusMsg();
  355.             }
  356.         } else {
  357.             user.mainmsg.setStatusMsg("Requested entry does not exist.", 10);
  358.             clearFields();
  359.         }
  360.  
  361.     }
  362.  
  363.     //
  364.     //  Save the selected item
  365.     //
  366.     public boolean saveData() {
  367.  
  368.         int recCount = 0;
  369.         Vector results = new Vector();
  370.         String sep = jaggSQL.getSEP();
  371.         String SQL = "";
  372.  
  373.         if (insertRequested) {
  374. >034            SQL = <INSERT INTO >;
  375.         } else {
  376.             itemIndex = searchResults.getSelectedIndex();
  377.             if (itemIndex < 0) {
  378.                 user.mainmsg.setStatusMsg("You must first make a selection",5);
  379.                 return false;
  380.             }
  381.             if (deleteRequested) {
  382. >035                SQL = <DELETE FROM >;
  383.             } else {
  384. >036                SQL = <UPDATE >;
  385.             }
  386.         }
  387.  
  388.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  389.         recCount = jaggSQL.execSQL(SQL, results);
  390.  
  391.         if(recCount == -1) {
  392.             System.out.println("saveData SQL: "+SQL);
  393.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator.", 10);
  394.             return false;
  395.         }
  396.         if(recCount == 1) {
  397.             if (insertRequested) {
  398.                 user.mainmsg.setStatusMsg("Record successfully added.",3);
  399.             } else 
  400.             if (deleteRequested) {
  401.                 user.mainmsg.setStatusMsg("Record successfully removed.",3);
  402.             } else {
  403.                 user.mainmsg.setStatusMsg("Record successfully updated.",3);
  404.             }
  405.         } else {
  406.             user.mainmsg.setStatusMsg("SQL failed. Contact the System Administrator.", 10);
  407.         }
  408.         insertRequested = false;
  409.         deleteRequested = false;
  410.         return true;
  411.  
  412.     }
  413.  
  414.     //
  415.     //  Clear the screen fields for a new option
  416.     //
  417.     public void clearFields() {
  418.  
  419. >037        <username>.setText("");
  420.  
  421.     }
  422.  
  423.     //
  424.     //  Load all of the Screen Choices
  425.     //
  426.     public void loadChoices() {
  427. >043
  428. >044        new JDPLoadChoice(user,jaggSQL,<choicename>,"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",value<columnname>);
  429.     }
  430.  
  431.     //
  432.     //  Perform component validations
  433.     //
  434.     public boolean checkFields() {
  435.  
  436. >045        if (!user.u.<isnumeric>(<field>,user.mainmsg)) return false;
  437.  
  438.         return true;
  439.  
  440.     }
  441.  
  442.  
  443. }
  444.